﻿using Infrastructure.Attribute;
using ZR.Model;
using ZR.Service;
using ZR.ServiceCore.Services.IService;
using IpRateLimitPolicy = ZR.ServiceCore.Model.IpRateLimitPolicy;

namespace ZR.ServiceCore.Services;

[AppService(ServiceType = typeof(IIpRateLimitPolicyService), ServiceLifetime = LifeTime.Transient)]
public class IpRateLimitPolicyService : BaseService<IpRateLimitPolicy>, IIpRateLimitPolicyService
{
    public async Task<PagedInfo<IpRateLimitPolicy>> SelectIpRateLimitPolicyPageAsync(IpRateLimitPolicy ipRateLimitPolicy, PagerInfo pager)
    {
        RefAsync<int> total = 0;
        var res = await Queryable()
            .Includes(it => it.Rules)
            .ToPageListAsync(pager.PageNum, pager.PageSize, total);
        var page = new PagedInfo<IpRateLimitPolicy>
        {
            PageSize = pager.PageSize,
            PageIndex = pager.PageNum,
            Result = res,
            TotalNum = total
        };
        return page;
    }
}